﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;
using System.Data;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

namespace TestIHM
{
    public partial class MainWindow : Window
    {        
        public TestPartie partie
        {
            get;
            set;
        }
        
        public MainWindow()
        {
            InitializeComponent();

            partie = new TestPartie();

            partie.setParametre(5);
        }

        public void ClickFin(object sender, RoutedEventArgs e)
        {
        }

        public void ClickU1(object sender, RoutedEventArgs e)
        {}
        public void ClickU2(object sender, RoutedEventArgs e)
        { }
        public void ClickU3(object sender, RoutedEventArgs e)
        { }
        public void ClickU4(object sender, RoutedEventArgs e)
        { }
        public void ClickU5(object sender, RoutedEventArgs e)
        { }
        public void ClickU6(object sender, RoutedEventArgs e)
        { }

        public void ClickActionAller(object sender, RoutedEventArgs e)
        {
        }
        public void ClickActionAttaquer(object sender, RoutedEventArgs e)
        {
            XmlSerializer ser = new XmlSerializer(typeof(DataSet));

            // Creates a DataSet; adds a table, column, and ten rows.
            DataSet ds = new DataSet("myDataSet"); // using System.Data;
            DataTable t = new DataTable("table1");
            DataColumn c = new DataColumn("thing");
            t.Columns.Add(c);
            ds.Tables.Add(t);
            DataRow r;
            for (int i = 0; i < 10; i++)
            {
                r = t.NewRow();
                r[0] = "Thing " + i;
                t.Rows.Add(r);
            }
            TextWriter writer = new StreamWriter("SauvegardeDataSet.xml");
            ser.Serialize(writer, ds);
            writer.Close();
        }

        public void ClickActionFonder(object sender, RoutedEventArgs e)
        {
            SaveFileDialog boiteSauvegarde = new SaveFileDialog();
            boiteSauvegarde.Filter = "Fichier xml(*.xml)|*.xml";

            if (boiteSauvegarde.ShowDialog() == System.Windows.Forms.DialogResult.OK) // using System.Windows.Forms;
            {
                sauvegarder(boiteSauvegarde.FileName);
            }
        }

        public void sauvegarder(string filename)
        {
            FileStream file = File.Open(filename, FileMode.OpenOrCreate);
            XmlSerializer ser = new XmlSerializer(typeof(TestPartie));  // using System.Xml.Serialization;
            ser.Serialize(file, partie);
            file.Close();
        }

        public void ClickActionCreerEt(object sender, RoutedEventArgs e)
        { }
        public void ClickActionCreerEns(object sender, RoutedEventArgs e)
        { }
        public void ClickActionCreerDir(object sender, RoutedEventArgs e)
        { }
    }
}

